import '../hb_router_annotation.dart';
import 'hb_annotation_item.dart';

extension _NavigationTypeToString on HBRoutePageNavigationType {

}

hbTplRender({List<HBAnnotationItem> pages, String projectName}) {

  final _lineFeedCharts = "\n\t";

  List<String> imports = [];
  List<String> routeNameKeys = [];
  List<String> pageCases = [];
  pages.forEach((element) {
    imports.add("import 'package:${element.refer}';");
    String routeKey = "const ${element.kRouteName} = '${element.routeUniKey}';";
    if (element.routeAnnotation?.isNotEmpty == true) {
      routeKey = "// ${element.routeAnnotation}"+"\n\t"+routeKey;
    }
    routeNameKeys.add(routeKey);
    String paramPart = element.haveParam ? "${element.paramKey}:param" : "";
    pageCases.add(
      "\tcase ${element.kRouteName}:\n\t\t"+"return CupertinoPageRoute(builder: (BuildContext context) => ${element.clazzName}($paramPart),settings: settings);"
    );
  });
  final importStr = imports.join(_lineFeedCharts);
  final routeNameKeyDesc = routeNameKeys.join(_lineFeedCharts);
  final pageCaseDesc = pageCases.join(_lineFeedCharts);
  final tpl = """
  
  import 'package:$projectName/components/hb_scaffold.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  $importStr
  
  // 路由名称
  $routeNameKeyDesc
  
  class HBRoutesManager {
  
    Route<dynamic> generateRoute(RouteSettings settings) {
      Object param = settings.arguments;
      switch (settings.name) {
        $pageCaseDesc
        default:
        return CupertinoPageRoute(
            builder: (_) => HBScaffold(
              body: Center(
                child: Text("当前界面不存在"),
              ),
            ));
      }
    }
  }
  """;

  return tpl;
}